package com.zhangck.bos_fore.action;

import java.util.UUID;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

import cn.itcast.bos.domain.base.Area;
import cn.itcast.bos.domain.take_delivery.Order;
import cn.itcast.crm.domain.Customer;

/** 
* @author 上午茶
* @version 创建时间：2018年6月11日 下午3:14:53 
* 类说明 
*/
@ParentPackage("json-default")
@Namespace("/")
@Scope("prototype")
@Actions
@Controller
@Service("orderServicesImpl")
public class OrderAction extends BaseAction<Order> implements MessageListener {

	private String sendAreaInfo;
	
	private String recAreaInfo;
	
	public void setSendAreaInfo(String sendAreaInfo) {
		this.sendAreaInfo = sendAreaInfo;
	}

	public void setRecAreaInfo(String recAreaInfo) {
		this.recAreaInfo = recAreaInfo;
	}

	@Action(value="orderAction_save",results={@Result(name="success", type="redirect", location="/index.html")})
	public String OrderAction_save(){
		System.out.println("滴滴滴");
		String[] split = sendAreaInfo.split("/");
		System.out.println(UUID.randomUUID().toString()+"aaaaaa");
		Area sendArea = new Area();
		sendArea.setProvince(split[0]);
		sendArea.setCity(split[1]);
		sendArea.setDistrict(split[2]);
		
		Area recdArea = new Area();
		recdArea.setProvince(split[0]);
		recdArea.setCity(split[1]);
		recdArea.setDistrict(split[2]);
		
		model.setSendArea(sendArea);
		model.setRecArea(recdArea);
		
		Customer customer = (Customer) ServletActionContext .getRequest().getSession().getAttribute("loginCustomer");
		
		model.setCustomer_id(customer.getId());
		
		//1.Accept属于请求头,客户端希望接受的数据类型。 ，Type属于实体头,客户端或服务器希望接受的实体数据类型。 
		WebClient.create("http://localhost:8080/bos_management/services/OrderServices/Order").type(MediaType.APPLICATION_JSON).post(model);
		
		System.out.println("进行了提交");
		
		return "success";
	}

	@Override
	public void onMessage(Message message) {
		MapMessage mapMessage = (MapMessage) message;
		try {
			String string = mapMessage.getString("telephone");
			String string2 = mapMessage.getString("msg");
			System.out.println(string);
			System.out.println(string2);
			System.out.println("监听到了");
		} catch (JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
